package com.gewu.pm.ui.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.gewu.pm.http.request.CeShiApi;
import com.hjq.http.EasyHttp;
import com.gewu.pm.R;
import com.gewu.pm.aop.SingleClick;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.http.callback.DialogCallback;
import com.gewu.pm.http.model.HttpData;
import com.gewu.pm.http.request.GetCodeApi;
import com.gewu.pm.utils.Constants;

import cn.jpush.android.api.JPushInterface;

/**
 * 网络请求测试
 */
public class TestHttpActivity extends AppActivity {
    private Button bt1;
    private Button bt2;
    private Button bt3;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_test_http;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        bt1 = findViewById(R.id.bt_1);
        bt2 = findViewById(R.id.bt_2);
        bt3 = findViewById(R.id.bt_3);
        setOnClickListener(bt1, bt2,bt3);
    }

    @SingleClick
    @Override
    public void onClick(View view) {
        if (view == bt1) {// 获取验证码
            EasyHttp.get(this)
                    .api(new GetCodeApi()
                            .setMobile("17312124501"))
                    .request(new DialogCallback<HttpData<String>>(this) {
                        @Override
                        public void onHttpSuccess(HttpData<String> result) {
                            super.onHttpSuccess(result);

                            toast("发送成功");
                        }
                    });
        }else if (view == bt2){
            postDelayed(() -> {
            JPushInterface.setAlias(this, Constants.MSG_SET_ALIAS, "QXKJ17312124501");
        }, 1000);

        }else if (view == bt3){
            postDelayed(() -> {
                JPushInterface.deleteAlias(this, Constants.MSG_SET_ALIAS);
            }, 1000);
        }
    }

    @Override
    protected void initData() {
        EasyHttp.get(this)
                .api(new CeShiApi())
                .request(new DialogCallback<HttpData<String>>(this) {
                    @Override
                    public void onHttpSuccess(HttpData<String> result) {
                        super.onHttpSuccess(result);

                        toast("发送成功");
                    }
                });
    }
}